<?php
   require("../configuracion.php");
   $idSysSection = $sectionHerrBanners;
   require("../application-top.php");
   
   $idBanner = $_GET['idBanner'];
   $fechadia = $_GET['dia'];
   
  $semana = array(
  '', 'Domingo', 'Lunes', 'Martes', 'Mi&eacute;rcoles', 
  'Jueves', 'Viernes', 'S&aacute;bado', 'Domingo');
?>
<html>
<head>
  <title><?= $instanciaECRM ?></title>
  <link rel="stylesheet" href="../styles/style.css" type="text/css">
</head>
<body leftmargin="0" class="mainBackground" topmargin="0" marginwidth="0" marginheight="0">
<table width="100" border="0" cellpadding="0" cellspacing="0">
  <tr><td><img src="../images/headerBar.gif" width="590" height="60" alt=""></td></tr>
  <tr>
    <td><table width="800" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td bgcolor="#FFFFFF" valign="top" height="400">

<table border="0" cellpadding="5" cellspacing="0" width="750">
  <tr><td colspan="2"><table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr><td colspan="2"><img src="../images/spacer.gif" height="10" width="1" alt=""></td></tr><tr>
     <td><strong class="pageTitle">Banners</strong><br><strong class="pageSubtitle">Reporte de Banners</strong></td>
	<td align="right"><a href="http://www.cacto.com/" target="_blank"><img src="../images/trademarkCacto.gif" alt="Cacto" border="0"></a><br><strong class="systemtitle"><?= $instanciaECRM ?></strong><br>Perfil <strong><?= $PerfilUsuario ?></td></tr>
  </table></td></tr>
  <tr>
  <td valign="top" width="100%">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr><td colspan="2">
        <table border="0" cellpadding="5" cellspacing="1" class="mainTableBG">
          <tr class="answerCellBG">
            <td><img src="../images/icArrowGo.gif" height="13" width="13" alt=""></td>
            <td><a href="javascript:history.back();" target="content">Regresar</a></td>
          </tr>
        </table>
      </td></tr>
      <tr><td colspan="2"><img src="../images/spacer.gif" height="10" width="1" alt=""></td></tr>
      <tr><td>
<!-- INICIO CUERPO DEL REPORTE -->	  
		<br>
	  <br>
	  <strong class="pageSubtitle">Banner</strong><br>
	  <br>
	<?php
	$queryFila  = " SELECT ";
	$queryFila .= " nombre_banner, BannerMedio, ";
	$queryFila .= " convert(char(10), fecha_publicacion, 103) as fecha, ";
	$queryFila .= " DATEDIFF(dd,fecha_publicacion,GETDATE()) as dias ";
	$queryFila .= " FROM tbl_Banners LEFT JOIN cat_BannerMedios ";
	$queryFila .= " ON tbl_Banners.id_BannerMedio = cat_BannerMedios.id_BannerMedio ";
	$queryFila .= " WHERE (tbl_Banners.id_Banner = ".$idBanner.");";
	$resFila = mssql_query($queryFila);
	$rowFila = mssql_fetch_object($resFila);
	$fecha = $rowFila->fecha;
	$dias = $rowFila->dias;
	
	?>	
	  <table border="0" cellpadding="5" cellspacing="1" class="secTableBG">
	   <tr class="mainTableBG">
		<td colspan="2" class="secTableTitle">Banner&nbsp;<strong><?php echo $rowFila->nombre_banner; ?></strong></td>
		</tr>
	   <tr class="answerCellBG">
		<td class="conceptCellBG" valign="top">Medio:</td>
		<td><?php echo $rowFila->BannerMedio; ?></td>
        </tr>
	   <tr class="answerCellBG">
		<td class="conceptCellBG" valign="top">Fecha Publicac&iacute;on:</td>
		<td><?php echo $fecha; ?></td>
        </tr>
	</table>	
	  <br>
	  <strong class="pageSubtitle"><?php echo $fechadia; ?><br>Detalle Horas</strong><br>
	  <br>
	<table border='0' cellpadding='5' cellspacing='1' class='secTableBG'>
	  <tr class="mainTableBG">
		<td class='secTableTitle'><strong>Hora</strong></td>
		<td class='secTableTitle' width="100"><strong>Impresiones</strong></td>
		<td class='secTableTitle' width="100"><strong>Clicks</strong></td>
		<td class='secTableTitle' width="100"><strong>CTR</strong></td>
	  </tr>
	<?php
	$class = "answerCellBG";
	$totalviews = 0;
	$totalclicks = 0;
  	for ($horadia = 0; $horadia < 24; $horadia++) {	
	
		$queryFila  = " SELECT count(*) as clicks ";
		$queryFila .= " FROM tbl_BannerClicks ";
		$queryFila .= " WHERE (DATEPART(hh,hora_click) = ".$horadia.") ";
		$queryFila .= " AND (fecha_click = convert(datetime,'".$fechadia."',103)) ";
		$queryFila .= " AND (id_Banner = ".$idBanner.");";
		$resFila   = mssql_query($queryFila);
		$rowFila = mssql_fetch_object($resFila);
		$clickshora = $rowFila->clicks;
		$queryFila  = " SELECT count(*) as views ";
		$queryFila .= " FROM tbl_BannerViews ";
		$queryFila .= " WHERE (DATEPART(hh,hora_view) = ".$horadia.") ";
		$queryFila .= " AND (fecha_click = convert(datetime,'".$fechadia."',103)) ";
		$queryFila .= " AND (id_Banner = ".$idBanner.");";
		$resFila   = mssql_query($queryFila);
		$rowFila = mssql_fetch_object($resFila);
		$viewshora = $rowFila->views;
	
		$lahora = $horadia;
		if (strlen($lahora) == 1) { $lahora = "0".$lahora; };
	
	?>	
	  <tr class="<?php echo $class; ?>">
		<td valign="middle"><img src="iconTime.gif">&nbsp;<?php echo $lahora; ?>:00:00 - <?php echo $lahora; ?>:59:59</td>
		<td align="right"><?php echo number_format($viewshora); ?></td>
		<td align="right"><?php echo number_format($clickshora); ?></td>
		<td align="right">0.00%</td>
	  </tr>
	<?php
		if ($class == "answerCellBG") {
			$class = "conceptCellBG";
		} else {	
			$class = "answerCellBG";
		}
		$totalviews = $totalviews + $viewshora;
		$totalclicks = $totalclicks + $clickshora;
	
	}
	?>
	  <tr>
		<td>&nbsp;</td>
		<td class='answerCellBG' align="right"><?php echo number_format($totalviews); ?></td>
		<td class='answerCellBG' align="right"><?php echo number_format($totalclicks); ?></td>
		<td class='answerCellBG' align="right">0.00%</td>
	  </tr>
	</table>


<br>
            <div align="right"><br><font color="#999999"><?= date("l, d/m/Y H:i:s") ?></font></div>
			  
<!-- FIN CUERPO DEL REPORTE -->	  
			  </td></tr>
    </table>
  </td>
  </tr>
</table>
          
          </td>
        </tr>
      </table></td>
  </tr>
</table>
<br>
<br>
<br>
<table width="750" border="0">
  <tr>
    <td align="right"><span class="copyright"><?= $copyright ?></span></td>
  </tr>
</table>
</body>
</html>
